<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="../include/tag.jsp" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>资金管理</title>
    <link rel="stylesheet" href="${ctx}/css/common/list.css">
    <link rel="stylesheet" href="${ctx}/css/common/table.css">
    <%@include file="../include/commonFile.jsp" %>
    <style type="text/css">
        thead th, tbody td {
            padding-left: 8px !important;
            padding-right: 8px !important;
        }
    </style>
</head>
<body>
<!--头部-->
<%@include file="../include/header.jsp" %>
<div class="index-outside">
    <%@include file="../include/sidebar.jsp" %>
    <!--内容-->
    <section>
        <div class="section-main">
            <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                <div class="member-index-top mt20">
                    <div class="top-left">

                        <div class="display-flex">
                            <div class="info-div" style="font-size:20px;display:inline">
                                <span>&nbsp;&nbsp;&nbsp;众筹累计资金： </span>
                                <span><b class="active-red">
                                        <c:if test="${orderTotal > 0}">
                                            <fmt:formatNumber pattern="#,###.##" value="${orderTotal}"/>
                                        </c:if>
				                    	<c:if test="${orderTotal == 0.0}">
                                            ${orderTotal}
                                        </c:if>
                                        </b>
                                    </span>
                            </div>
                            <div class="info-div" style="font-size:20px;display:inline">
                                <span>&nbsp;&nbsp;&nbsp;总可提现金额： </span>
                                <span><b class="active-red">
                                        <c:if test="${totalAleAmount > 0}">
                                            <fmt:formatNumber pattern="#,###.##" value="${totalAleAmount}"/>
                                        </c:if>
				                    	<c:if test="${totalAleAmount == 0.0}">
                                            ${totalAleAmount}
                                        </c:if>
                                        </b>
                                    </span>
                            </div>
                            <div class="info-div" style="font-size:20px;display:inline">
                                <span>&nbsp;&nbsp;&nbsp;已提现金额： </span>
                                <span><b class="active-red">
                                        <c:if test="${edWithdrawalsAmount > 0}">
                                            <fmt:formatNumber pattern="#,###.##" value="${edWithdrawalsAmount}"/>
                                        </c:if>
				                    	<c:if test="${edWithdrawalsAmount == 0.0}">
                                            ${edWithdrawalsAmount}
                                        </c:if>
                                        </b>
                                    </span>
                            </div>
                            <div class="info-div" style="font-size:20px;display:inline">
                                <span>&nbsp;&nbsp;&nbsp;当前可提现金额： </span>
                                <span><b class="active-red">
                                        <c:if test="${ingWithdrawalsAmount > 0}">
                                            <fmt:formatNumber pattern="#,###.##" value="${ingWithdrawalsAmount}"/>
                                        </c:if>
				                    	<c:if test="${ingWithdrawalsAmount == 0.0}">
                                            ${ingWithdrawalsAmount}
                                        </c:if>
                                        </b>
                                    </span>
                            </div>
                        </div>
                    </div>

                </div>
                <%--<div class="layui-tab-content">--%>
                    <%--<div class="f-search-bar">--%>
                        <%--<div class="search-container">--%>
                            <%--<ul class="search-form-content">--%>
                                <%--<li class="form-item"><label class="search-form-lable"></label>--%>
                                    <%--<div class="check-btn-inner">--%>
                                        <%--<c:if test="${finalPaymentOF}">--%>
                                            <%--<a class="active"--%>
                                               <%--href="${ctx}/moneyManagement/tailParagraph/tailParagraphInfo.do?businessId=${ceObj.id}&memberId=${ceObj.createBy}"--%>
                                            <%-->尾款详情</a>--%>
                                        <%--</c:if>--%>
                                    <%--</div>--%>
                                <%--</li>--%>
                            <%--</ul>--%>
                        <%--</div>--%>
                    <%--</div>--%>

                    <div class="layui-tab-content">
                        <div class="f-search-bar">
                            <div class="search-container">
                                <ul class="search-form-content">
                                    <li class="form-item"><label class="search-form-lable"></label>
                                        <div class="check-btn-inner">
                                            <c:if test="${!withdrawalOF}">
                                                <a class="active" onclick="withdrawDeposit('${memberId}','${ceObj.id}','${memberPartner.partnerType}','${withdrawalCharge}')">
                                                    提现</a>
                                            </c:if>
                                            <c:if test="${asOFEventDate}">
                                                <c:if test="${finalPaymentOF}">
                                                    <a class="active"
                                                       href="${ctx}/moneyManagement/tailParagraph/tailParagraphInfo.do?businessId=${ceObj.id}&memberId=${ceObj.createBy}"
                                                    >尾款详情</a>
                                                </c:if>
                                                <c:if test="${!finalPaymentOF}">
                                                    <a class="active"
                                                       onclick="tailParagraphWithdrawal('${memberId}','${ceObj.id}')">尾款提现</a>
                                                </c:if>
                                            </c:if>
                                        </div>
                                    </li>
                                </ul>
                            </div>
                        </div>

                    <div class="layui-tab-item layui-show">
                        <form class="layui-form" action="${ctx}/moneyManagement/withdrawalInfo.do"
                              id="myForm" method="post">
                            <input type="hidden" name="pageNo" id="pageNo"/>
                            <input type="hidden" name="memberId" id="memberId" value="${memberId}"/>
                            <input type="hidden" name="eventId" id="eventId" value="${ceObj.id}"/>
                        </form>
                        <div class="my-act-list-content">
                            <div class="cl">
                                <table class="layui-table">
                                    <colgroup>
                                        <col width="120">
                                        <col width="120">
                                        <col width="120">
                                        <col width="120">
                                        <col width="120">
                                    </colgroup>
                                    <thead>
                                    <tr>
                                        <th>提现时间</th>
                                        <th>提现金额</th>
                                        <th title="提现金额x(微信提现手续费(0.006)+平台提现手续费)">手续费</th>
                                        <th>实际到账</th>
                                        <th>状态</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <c:if test="${page.totalCount == 0}">
                                        <tr>
                                            <td colspan="5">
                                                <div class="f18 tc">还没有提现记录</div>
                                            </td>
                                        </tr>
                                    </c:if>
                                    <c:forEach var="withdrawal" items="${withdrawals}">
                                        <tr>
                                            <td><fmt:formatDate value="${withdrawal.createDate}"
                                                                pattern="yyyy-MM-dd HH:mm"/></td>
                                            <td><fmt:formatNumber pattern="0.00" value="${withdrawal.payment}"/>元</td>
                                            <td><fmt:formatNumber pattern="0.00" value="${withdrawal.serviceFee}"/>元
                                            </td>
                                            <td><fmt:formatNumber pattern="0.00" value="${withdrawal.netAmount}"/>元</td>
                                            <td title="${withdrawal.remarks}">
                                                <c:if test="${withdrawal.status == 1 or withdrawal.status == 4}">
                                                    <span>处理中</span>
                                                </c:if>
                                                <c:if test="${withdrawal.status == 2}">
                                                    <span style="color: green;">已付款</span>
                                                </c:if>
                                                <c:if test="${withdrawal.status == 3}">
                                                    <span><a href="javascript:showAuthor1('${withdrawal.remarks}')"
                                                             class="red">已拒绝&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #5e5e5e">▼</span></a> </span>
                                                </c:if>
                                            </td>
                                        </tr>
                                    </c:forEach>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <div class="page-content">
                            <c:if test="${page.totalCount > 0}">
                                <div class="l page-totalcount">
								<span class="f14 red">共<b id="totalCount">${page.totalCount}</b>条记录
								</span>
                                </div>
                            </c:if>
                            <div id="page_content" class="page-container"></div>
                        </div>
                    </div>
                    <div class="layui-tab-item"></div>
                </div>
            </div>
        </div><!--底部-->
        <%@include file="../include/footer.jsp" %>
    </section>
    <div id="authorDialog1">
        <table class="layui-table" lay-skin="line">
            <tbody>
            <tr>
                <td class="table-member">
                    <div class="member-cell">
                        <div class="member-name ellipsis-1">

                        </div>
                    </div>
                </td>
            </tr>
            </tbody>
        </table>
    </div>
    <div id="withdrawDiv" style="padding: 0px 10px">
        <div>
            <form id="withdrawForm" class="layui-form mt20" method="post"
                  action="${ctx}/moneyManagement/initiateDrawings.do">
                <input type="hidden" name="eventId" value=""/>
                <input type="hidden" name="serviceFee" value="">
                <input type="hidden" name="memberId" value="">
                <div class="cl">
                    <table class="layui-table">
                        <tbody>
                        <tr>
                            <td>
                                <div class="info-div" style="display:inline">
                                    <span>当前可提现金额： </span>
                                    <span><b>
                                        <input type="text" readonly="readonly" contenteditable="true"
                                               style="width:150px;font-size:20px;"
                                               name="ingWithdrawalsAmount" class="active-red" class="layui-input"/>元
                                        </b>
                                    </span>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td><label class="layui-form-label">姓名：</label>
                                <div class="layui-input-inline">
                                    <span id="name" class="layui-input"
                                          style="border: 0px; height: 38px; line-height: 38px;"/>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td><label class="layui-form-label">提现银行：</label>
                                <div class="layui-input-inline">
                                    <span id="bankName" class="layui-input"
                                          style="border: 0px; height: 38px; line-height: 38px;"/>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td><label class="layui-form-label">开户行：</label>
                                <div class="layui-input-inline">
                                    <span id="openedPlace" class="layui-input"
                                          style="border: 0px; height: 38px; line-height: 38px;"/>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td><label class="layui-form-label">银行卡号：</label>
                                <div class="layui-input-inline">
                                    <span id="accountNumber" class="layui-input"
                                          style="border: 0px; height: 38px; line-height: 38px;"/>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td><label class="layui-form-label">提现金额<span class="f-verify-red">*</span>：</label>
                                <div class="layui-input-inline">
                                    <input type="number" min="1" style="width:250px;" name="payment" autocomplete="off"
                                           class="layui-input payment"
                                           lay-verify="payment" placeholder="请输入要提现的金额" value="">
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td title="提现金额x(微信提现手续费(0.006)+平台提现手续费)"><label class="layui-form-label">手续费<span
                                    class="f-verify-red">*</span>：</label>
                                <div class="layui-input-inline">
                                    <span id="serviceFee" class="layui-input"
                                          style="border: 0px;height: 38px; line-height: 38px;"/>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td><label class="layui-form-label"></label>
                                <div class="layui-input-inline" style="width: 270px;">
                                    <div class="cl">
                                        <p>注：</p>
                                        <dl id="dl_id" style="line-height: 25px;">
                                            <dt>1.微信费率：微信提现费率6‰；</dt>
                                            <dt>2.实际到账=提现金额 —提现金额x6‰；</dt>
                                            <dt>3.当天18点前申请的提现，当天审核，预计1-7个工作日到账。超过18点后申请的提现，则往后推迟一个工作日。节假日顺延。</dt>
                                        </dl>
                                    </div>
                                </div>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </form>
        </div>
    </div>
    <div id="tailParagraphWithdrawalDiv" style="padding: 0px 10px">
        <form id="tailParagraphWithdrawalForm" class="layui-form mt20" method="post"
              action="${ctx}/moneyManagement/tailParagraph/initiateDrawings.do">
            <input type="hidden" name="eventId" value=""/>
            <input type="hidden" name="memberId" value=""/>
            <div class="layui-form-item layui-form-text">
                <div class="layui-input-block">是否确认申请尾款提现？</div>
                <div class="layui-input-block">
                        <textarea name="noteMessage" style="width: 250px;"
                                  placeholder="请填写备注" class="layui-textarea"></textarea>
                </div>
            </div>
        </form>
    </div>
</div>

<script type="text/javascript" src="${ctx}/script/common/list.js"></script>
<script type="text/javascript">

    $(function () {
        txz.initHeader({
            nav: [{
                name: '资金管理',
                curr: true
            }, {
                name: '${ceObj.name}'
            }, {
                name: '提现详情',
                curr: true
            }],
            info: '',
            btns: [{
                name: '返回',
                href: '${ctx}/moneyManagement/crowdFundingMoneyList.do?memberId=${memberId}',
                icon: 'back'
            }]
        });

        //加载分页
        loadPageNew({
            elem: 'page_content',
            totalCount: '${page.totalCount}',
            limit: '${page.limit}',
            page: '${page.page}'
        });
        $("[name=payment]").bind('input propertychange blur', function (e) {
            var value = $(this).val();
            if (value != "") {
                var serviceFee = $("[name=serviceFee]").val();

                value = parseFloat(value) * serviceFee;
                console.log(value)
                $("#serviceFee").text(value.toFixed(2) + "元");
            } else {
                $("#serviceFee").text("");
            }
        });
    })

    function showAuthor1(remarks) {
        var setPayIndex = layer.open({
            type: 1,
            area: '400px',
            title: '查看备注',
            content: $("#authorDialog1"),
            btn: ['关闭'],
            success: function () { // 弹出后回调
                if (remarks != null && remarks.length > 0) {
                    $("#authorDialog1").find(".member-name").text(remarks);
                } else {
                    util.layerMsgError("暂无备注");
                }
            },
            end: function () { // 销毁后回调
                $("#authorDialog1").find(".member-name").text('');
            },
            yes: function () { // 确定按钮
                layer.close(setPayIndex);
            }
        });
    }

    /**
     * 普通提现
     * @param eventId
     */
    function withdrawDeposit(memberId,eventId,partnerType,withdrawalCharge) {

        $.post("${ctx}/moneyManagement/getMemberWithdrawalInfo.do", {
            eventId: eventId,
            memberId:memberId
        }, function (data) {
            setTimeout(function () {
                if (data.success) {

                    $("#withdrawDiv #withdrawForm").show();
                    $("#withdrawDiv #withdrawForm [name=ingWithdrawalsAmount]").val(data.data.ingWithdrawalsAmount)
                    $("#withdrawDiv #withdrawForm [name=serviceFee]").val(data.data.serviceFee);
                    $("#withdrawDiv #withdrawForm [name=eventId]").val(eventId);
                    $("#withdrawDiv #withdrawForm [name=memberId]").val(memberId);
                    $("#name").text(data.data.memberBank.name)
                    $("#bankName").text(data.data.memberBank.bankName)
                    $("#openedPlace").text(data.data.memberBank.openedPlace)
                    $("#accountNumber").text(data.data.memberBank.accountNumber)

                    if(partnerType==0&&withdrawalCharge!=null&&withdrawalCharge>0){
                        $("#dl_id").append("<dt id='sdt_id'>4.平台手续费："+withdrawalCharge+"%</dt>")
                    }
                    var lock = false;
                    var checkIndex = layer.open({
                        type: 1,
                        area: ['550px', '630px'],
                        title: '提现申请',
                        content: $("#withdrawDiv"),
                        btn: ['确定提现', '取消'],
                        yes: function () {


                            var payment = $("#withdrawDiv #withdrawForm [name=payment]").val();

                            if (payment == '') {
                                layer.msg("请输入正确的提现金额", {title: '提现申请通知', icon: 2, time: 2000});
                            } else if (payment == 0) {
                                layer.msg("请输入正确的提现金额", {title: '提现申请通知', icon: 2, time: 2000});
                            } else if (payment < 0.01) {
                                layer.msg("提现金额不能少于0.01", {title: '提现申请通知', icon: 2, time: 2000});
                            } else {
                                if (!lock) {
                                    lock = true
                                    $.post($("#withdrawDiv #withdrawForm").attr('action'),
                                        $("#withdrawDiv #withdrawForm").serialize(), function (res) {
                                            if (res.success) {
                                                layer.msg('提现申请成功', {
                                                    title: '提现申请通知',
                                                    icon: 1,
                                                    time: 2000
                                                }, function () {
                                                    window.location.reload();
                                                });
                                            } else {
                                                layer.msg(res.description, {title: '提现申请通知', icon: 2, time: 2000});
                                            }
                                        });
                                }
                            }
                        },
                        end: function () {//取消按钮
                            $("#serviceFee").text("");
                            $("#withdrawDiv #withdrawForm [name=payment]").val('')

                            if($("#sdt_id").length>0){
                                $("#sdt_id").remove()
                            }
                            layer.close(checkIndex);

                        }
                    });

                } else {
                    util.layerAlertError(data.description)
                }
            }, 200);
        })
    }

    /**
     * 尾款提现
     * @param eventId
     */
    function tailParagraphWithdrawal(memberId,eventId) {

        $("#tailParagraphWithdrawalDiv #tailParagraphWithdrawalForm").show();
        $("#tailParagraphWithdrawalDiv #tailParagraphWithdrawalForm [name=eventId]").val(eventId);
        $("#tailParagraphWithdrawalDiv #tailParagraphWithdrawalForm [name=memberId]").val(memberId);
        var lock = false;
        var checkIndex = layer.open({
            type: 1,
            area: ['460px', '280px'],
            title: '尾款提现申请',
            content: $("#tailParagraphWithdrawalDiv"),
            btn: ['确定提现', '取消'],
            yes: function () {
                if (!lock) {
                    lock = true
                    $.post($("#tailParagraphWithdrawalDiv #tailParagraphWithdrawalForm").attr('action'),
                        $("#tailParagraphWithdrawalDiv #tailParagraphWithdrawalForm").serialize(), function (res) {
                            if (res.success) {
                                layer.msg('尾款提现申请成功', {title: '尾款提现申请通知', icon: 1, time: 2000}, function () {
                                    window.location.reload();
                                });
                            } else {
                                layer.msg(res.description, {title: '尾款提现申请通知', icon: 2, time: 2000});
                            }
                        });
                }
            },
            end: function () {//取消按钮
                $("#tailParagraphWithdrawalDiv #tailParagraphWithdrawalForm [name=eventId]").val('')
                $("#tailParagraphWithdrawalDiv #tailParagraphWithdrawalForm [name=noteMessage]").val('')
                layer.close(checkIndex);
            }
        });
    }

</script>
</body>
</html>